<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
       function validateInput(promptMessage) {
            let input = prompt(promptMessage);
             if (input === null || isNaN(input) || Number(input) <= 0) {
                alert("请输入一个非零、非负数的数值类型。");
                return null;
    }
    return Number(input);
}

let numSubjects = validateInput("请输入考试科目的数量：");
if (numSubjects === null) {
    alert("程序已退出。");
} else {
    let totalScore = 0;
    for (let i = 1; i <= numSubjects; i++) {
        let score = validateInput(`请输入第 ${i} 科的考试成绩：`);
        if (score === null) {
            alert("程序已退出。");
            break;
        }
        totalScore += score;
    }
    alert(`所有科目的考试成绩总和为：${totalScore}`);
}

    </script>
</head>
<body>
    
</body>
</html>